<template>
	<view>
		<u-navbar :is-back="true" title="添加服务" :background="{backgroundColor: '#00a8ff'}"></u-navbar>
		<u-search style="width: 100%;" placeholder="请输入服务名称" :clearabled="false"
			v-model="serch" :show-action="false" class="u-p-26">
		</u-search>
		<view class="u-p-12">
			<u-waterfall v-model="flowList" ref="uWaterfall">
				<template v-slot:left="{leftList}">
					<view class="u-p-12" v-for="(item, index) in list1" :key="index">
						<u-lazy-load threshold="-450" border-radius="10" :image="oss+item.image" :index="index">
						</u-lazy-load>
						<view class="demo-title">
							{{item.name}}
						</view>
						<view class="demo-shop">
							¥{{item.product.price}}
							<u-button type="primary" v-if="item.is_add=='false'" shape="circle" class="u-close" plain
								size="mini" @click="addgoods(item.id)">添加</u-button>
							<u-button type="default" v-else-if="item.is_add=='true'" shape="circle" class="u-close"
								plain size="mini">已添加</u-button>
						</view>
					</view>
				</template>
				<template v-slot:right="{rightList}">
					<view class="u-p-12" v-for="(item, index) in list2" :key="index">
						<u-lazy-load threshold="-450" border-radius="10" :image="oss+item.image" :index="index">
						</u-lazy-load>
						<view class="demo-title">
							{{item.name}}
						</view>
						<view class="demo-shop">
							¥{{item.product.price}}
							<u-button type="primary" v-if="item.is_add=='false'" shape="circle" class="u-close" plain
								size="mini" @click="addgoods(item.id)">添加</u-button>
							<u-button type="default" v-else-if="item.is_add=='true'" shape="circle" class="u-close"
								plain size="mini">已添加</u-button>
						</view>
					</view>
				</template>
			</u-waterfall>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				serch: '',
				oss: 'http://zjmeifeng.oss-cn-beijing.aliyuncs.com',
				flowList: [],
				list1: [],
				list2: [],
			}
		},
		onLoad() {
			this.serverList();
		},
		methods: {
			serverList() {
				this.$apiVipCentre.goodslist({
					limit: '',
					page: '',
					search: '',
					cat_id: '',
					orderby: ''
				}).then((res) => {
					console.log("服务列表: ", res.data.data.items);
					let arr = res.data.data.items;
					let arr1 = [],
						arr2 = [];
					for (let i = 0; i < arr.length; i++) {
						if (i % 2 == 0) {
							arr1.push(arr[i])
						} else {
							arr2.push(arr[i])
						}
					}
					console.log(arr1);
					console.log(arr2);
					this.list1 = arr1;
					this.list2 = arr2;

				}).catch((err) => {
					console.log('request fail', err);
				})
			},
			// 添加服务
			addgoods(id) {
				this.$apiVipCentre.addgoods({
					goods_id: id
				}).then((res) => {
					console.log("添加消息: ", res.data.msg);

					setTimeout(() => {
						this.serverList();
					}, 500)
				}).catch((err) => {
					console.log('request fail', err);
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.popupView {
		border-radius: 10rpx;
		background-color: #f4f4f7;
	}

	.u-close {
		float: right;
		position: relative;
		top: -10rpx;
	}

	.demo-image {
		width: 100%;
		border-radius: 4px;
	}

	.demo-title {
		font-size: 30rpx;
		margin-top: 5px;
		color: $u-main-color;
	}

	.demo-shop {
		font-size: 22rpx;
		color: $u-tips-color;
		margin-top: 5px;
	}

	.demo-tag {
		display: flex;
		margin-top: 5px;
	}

	.demo-tag-text {
		border: 1px solid $u-type-primary;
		color: $u-type-primary;
		margin-left: 10px;
		border-radius: 50rpx;
		line-height: 1;
		padding: 4rpx 14rpx;
		display: flex;
		align-items: center;
		border-radius: 50rpx;
		font-size: 20rpx;
	}

	.demo-price {
		font-size: 30rpx;
		color: $u-type-error;
		margin-top: 5px;
	}
</style>
